// eslint-disable-next-line import/no-extraneous-dependencies
import { defineConfig } from 'vite';
import { resolve } from 'path';
import { envResolver } from './config';
import { getPlugins } from './config/plugins';

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => Object.assign(
    envResolver[mode](),
    {
        base: '/',
        // optimizeDeps: ['@dcloudio/uni-ui', '@/uview-plus'], // https://uniapp.dcloud.net.cn/component/uniui/quickstart.html
        optimizeDeps: {
            included: ['/src/uview-plus', '/src/wxcomponents/verify_mpsdk']
        },
        server: {
            // 是否开启 https
            https: false,
            // 端口号
            port: 4000,
            // 监听所有地址 127.0.0.1  localhost   192.168.1.x
            host: '0.0.0.0',
            // 服务启动时是否自动打开浏览器
            open: true,
            // 允许跨域
            cors: true
        },
        envDir: resolve(__dirname, 'config/env'),
        resolve: {
            alias: {
                '@': resolve(__dirname, 'src'),
            },
        },
        plugins: getPlugins(mode),
        build: {
            sourcemap: true,
        },
        transpileDependencies: ['uview-plus']
    },
));
